class Solution:
    def compareVersion(self, version1: str, version2: str) -> int:
        version1 = version1.split(".")
        version2 = version2.split(".")
        i = j = 0
        m, n = len(version1), len(version2)
        while i < m or j < n:
            if i == m: # 版本2没结束，说明更高
                if int(version2[j]) > 0:
                    return -1
                else:
                    j += 1
                    continue
            elif j == n: # 版本1没结束，更高
                if int(version1[i]) > 0:
                    return 1
                else:
                    i += 1
                    continue
                
            # 转化为整数比较
            if int(version1[i]) > int(version2[j]):
                return 1
            elif int(version1[i]) < int(version2[j]):
                return -1
            else:
                i += 1
                j += 1
        return 0